package com.xiaowu.netmusic.controller;

import com.xiaowu.netmusic.domain.vo.SongVO;
import com.xiaowu.netmusic.service.FavoriteService;
import com.xiaowu.netmusic.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

@RestController
@RequestMapping("/api/favorite")
@AllArgsConstructor
@Tag(name = "收藏管理", description = "提供用户歌曲收藏相关接口")
public class FavoriteController {

    private final FavoriteService favoriteService;

    @Operation(summary = "添加收藏", description = "用户收藏指定的歌曲")
    @PostMapping("/add")
    public Result<?> add(@RequestParam Long userId, @RequestParam Long songId) {
        boolean success = favoriteService.addFavorite(userId, songId);
        return success ? Result.success() : Result.error("收藏失败");
    }

    @Operation(summary = "取消收藏", description = "用户取消收藏指定的歌曲")
    @DeleteMapping("/remove")
    public Result<?> remove(@RequestParam Long userId, @RequestParam Long songId) {
        boolean success = favoriteService.removeFavorite(userId, songId);
        return success ? Result.success() : Result.error("取消收藏失败");
    }

    @Operation(summary = "获取收藏列表", description = "获取指定用户收藏的歌曲列表")
    @GetMapping("/list")
    public Result<List<SongVO>> list(@RequestParam Long userId) {
        List<SongVO> songList = favoriteService.getFavoriteSongs(userId);
        return Result.success(songList);
    }

    @Operation(summary = "检查是否已收藏", description = "判断用户是否已收藏某首歌曲")
    @GetMapping("/check")
    public Result<Boolean> check(@RequestParam Long userId, @RequestParam Long songId) {
        return Result.success(favoriteService.isFavorite(userId, songId));
    }
}
